package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

func main() {
	db, _ := sql.Open(
		"mysql",
		"root:root@tcp(172.20.0.10:3306)/gogogo?charset=utf8&parseTime=true&loc=Local",
	)
	defer db.Close()
	deleteStudent(db, 1)
}

func deleteStudent(db *sql.DB, id int) {
	stmt, _ := db.Prepare("delete from tbl_student where id = ?")
	result, err := stmt.Exec(id)
	if err != nil {
		log.Println("delete student error.", err.Error())
		return
	}
	rowsAffected, err := result.RowsAffected()
	if err != nil {
		log.Println("get row affected error", err.Error())
		return
	}
	fmt.Println("delete row num =", rowsAffected)
}

